<template>
  <div>
    <h2 align="center">投资项目列表</h2>
    项目名称:<input type="text" v-model="showData.T_Name">
    投资总金额:<input type="text" v-model="showData.MinMoney">--
    <input type="text" v-model="showData.MaxMoney">
    <input type="button" value="查询" class="btn btn-success" @click="getList">
    <table class="table table-bordered">
      <tr>
        <td>投资名称</td>
        <td>投资总额度</td>
        <td>已投资额度</td>
        <td>剩余额度</td>
        <td>投资人数</td>
        <td>操作</td>
      </tr>

      <tr v-for="item in list" :key="item.T_Id">
        <td>{{ item.T_Name }}</td>
        <td>{{ item.T_Total }}</td>
        <td>{{ item.T_Alright }}</td>
        <td>{{ item.T_Last }}</td>
        <td>{{ item.T_Number }}</td>
        <td>
          <input type="button" value="删除" class="btn btn-danger" @click="delData(item.T_Id)">&nbsp;
          <input type="button" value="修改" class="btn btn-primary" @click="editData(item.T_Id)">
        </td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">

import {reactive,toRefs,onMounted} from 'vue'
import { useRouter,useRoute } from 'vue-router'
import axios from 'axios'

let router = useRouter()

let route = useRoute()

//数据
let data =reactive({
  list:[],
  showData:{
    T_Name:'',
    MinMoney:'',
    MaxMoney:''
  }
})

//解构
let {list,showData} = toRefs(data)

onMounted(()=>{
  //获取列表
  getList()
})

//显示方法
const getList =()=>{
  axios({
    url:'/api/Invest/ShowList',
    method:'get',
    params:showData.value
  }).then(res=>{
    console.log(res);
    list.value = res.data.data
  }).catch(err=>{
    //异常处理
    console.log(err);
  })
}

//删除
const delData = (T_Id:number)=>{
  //确认删除吗
  const f = confirm('确认删除吗？')
  if(f){
    axios({
    url:'/api/Invest/DelById',
    method:'get',
    params:{
      T_Id:T_Id
    }
  }).then(res=>{
    console.log(res);
    if(res.data.data >0){
      alert('删除成功')
      getList()
    }else{
      alert('删除失败')
    }
  }).catch(err=>{
    console.log(err);
    
  })
  }
}

//修改
const editData = (T_Id:number)=>{
  router.push({
    path:'/upInvest',
    query:{
      T_Id:T_Id
    }
  })
}
</script>

<style scoped>

</style>